home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / bbs / mhis020.zip / STRING.MH < prev    next >
Text File  |  1996-08-21  |  4KB  |  96 lines

  1. // (C) 1995 Stefan Xenos
  2. //
  3. // This file defines various string manipulation functions. For more string-related
  4. // operations, see the file char.mh, which includes operations between characters
  5. // and strings.
  6. //
  7. // void         stripRight              (Ref string: theString, int: pos);
  8. // void         stripLeft               (Ref string: theString, int: pos);
  9. // void         stripRightOf            (Ref string: theString, char: toStripFrom);
  10. // void         stripNonNumeric         (Ref string: theString);
  11. // void         stripStr                (Ref string: sourceString, string: toStrip);
  12. //
  13. // string       stripLeftf              (string: theString, int: pos);
  14. // string       stripRightf             (string: theString, int: pos);
  15. // string       stripRightOff           (string: theString, char: toStripFrom);
  16. // string       stripNonNumericf        (string: theString);
  17. // string       stripStrf               (string: sourceString, string: toStrip);
  18. //
  19. // bool         findAllChars            (string: toSearch, string: charsToSearchFor);
  20. // bool         findAnyChars            (string: toSearch, string: charsToSearchFor);
  21. //
  22. // void         stringInit              ();
  23. // bool         stringToken             (string: token, string: params);
  24. //
  25.  
  26. #ifndef __STRING_MH
  27. #define __STRING_MH
  28.  
  29. //#ifndef __CHAR_MH
  30. //#include "char.mh"
  31. //#endif
  32.  
  33. // Erases everything after a particular position in a string. The position is
  34. // given by pos. The character at pos is deleted as well. The original string
  35. // is modified.
  36.  
  37. void stripRight (Ref string: theString, int: pos) {
  38.   theString := substr (theString, 1, pos - 1);
  39.   }
  40.  
  41. // Erases everything after a particular position in a string. The position is
  42. // given by pos. The character at pos is deleted as well. Returns the new string
  43. // without modifying the original string.
  44.  
  45. //string stripRightf (string: theString, int: pos) {
  46. //  stripRight (theString, pos);
  47. //  return theString;
  48. //  }
  49.  
  50. // Erases everything before a particular position in a string. The position is
  51. // given by pos. The character at pos is deleted as well. The original string
  52. // is modified.
  53.  
  54. //void stripLeft (Ref string: theString, int: pos) {
  55. //  theString := substr (theString, pos + 1, strlen (theString) - pos);
  56. //  }
  57.  
  58. // Erases everything before a particular position in a string. The position is
  59. // given by the parameter pos. The character at pos is deleted as well. The
  60. // new string is returned without modifying the original string.
  61.  
  62. //string stripLeftf (string: theString, int: pos) {
  63. //  stripLeft (theString, pos);
  64. //  return theString;
  65. //  }
  66.  
  67. // Searches for the first occourance of stripChar in the given string, then
  68. // erases the remainder of the string - including stripChar. This is useful
  69. // for eliminating comments from the end of lines in input files. The original
  70. // string is modified.
  71.  
  72. void stripRightOf (Ref string: theString, char: stripChar) {
  73.   int: idx;
  74.  
  75.   idx := stridx (theString, 1, stripChar);
  76.   if (idx) theString := substr (theString, 1, idx - 1);
  77.   }
  78.  
  79. // Same as above, but does not modify the original string.
  80.  
  81. //string stripRightOff (string: theString, char: stripChar) {
  82. //  stripRightOf (theString, stripChar);
  83. //  return theString;
  84. //  }
  85.  
  86.  
  87. // Same as above, but the original string is not modified - the new string
  88. // is returned by the function.
  89.  
  90. //string stripStrf (string: theString, string: s) {
  91. //  stripStr (theString, s);
  92. //  return theString;
  93. //  }
  94.  
  95. #endif
  96.